package guoanmaker.operator.business.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import guoanmaker.operator.business.model.OperatorCoupons;


public interface OperatorCouponsRepository extends  JpaRepository<OperatorCoupons, String>, JpaSpecificationExecutor<OperatorCoupons> {

	@Query("select  o from OperatorCoupons  o where o.couponsname=:couponsname and o.delestatus!=1")
	public List<OperatorCoupons>  selectByCouponsname(@Param("couponsname") String couponsname);
	@Transactional
	@Modifying
	@Query("UPDATE OperatorCoupons set beenused=beenused+1  where id=:id")
	public void updateBeenusedByid(@Param("id") String id);
	
	@Query("select sum(o.beensent) from OperatorCoupons o where o.delestatus!=1 and o.iseffect=1")
	public int  selectByCouponsSentnum();
	
	@Query("select sum(o.beenused) from OperatorCoupons o where o.delestatus!=1 and o.iseffect=1")
	public int  selectByCouponsusednum();
	
	@Query("select sum(o.totalcost) from OperatorCoupons o where o.delestatus!=1 and o.iseffect=1")
	public double  selectByCouponsAmount();
	
	@Transactional
	@Modifying
	@Query("UPDATE OperatorCoupons set beensent=beensent+1  where id=:id")
	public void updateBeensentByid(@Param("id") String id);
	
	
	
	
	
}
